from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SKUImage, SKU
from meiduo_admin.serlizer.images import ImagesSerializer, SKUSerializer
from meiduo_admin.utils import PageNum
from rest_framework.permissions import IsAdminUser

class ImagesView(ModelViewSet):
    # 指定序列花期
    serializer_class = ImagesSerializer
    # 指定查询集
    queryset = SKUImage.objects.all()
    # 指定分页
    pagination_class = PageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    def simple(self, request):
        '''获取sku信息'''
        # 查询所有sku商品
        skus = SKU.objects.all()
        # 序列化操作
        ser = SKUSerializer(skus, many=True)
        return Response(ser.data)
